package com.training1.core.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.training1.core.common.controller.BaseController;
import com.training1.core.common.dao.Page;
import com.training1.core.common.entity.BOXUserEntity;
import com.training1.core.common.entity.RespJson;
import com.training1.core.common.global.signIn.BOXLoginInfoUtil;
import com.training1.core.common.utils.framework.RespJsonFactory;
import com.training1.core.entity.ContractBaseEntity;
import com.training1.core.entity.ContractEXEEntity;
import com.training1.core.entity.CustomerEntity;
import com.training1.core.modules.service.BOXLoginService;
import com.training1.core.modules.service.ContractBaseService;
import com.training1.core.modules.service.ContractEXEService;
import com.training1.core.modules.service.CustomerService;


@Controller
@RequestMapping("contractterminate")
public class ContractTerminateController extends BaseController{
	@Resource
	private CustomerService customerService;
	@Resource
	private ContractEXEService contractEXEService;
	@Resource
	private ContractBaseService cbs;
	@Resource
	private BOXLoginService bls;
	
	@RequestMapping("contractterminatesetting")
	public String contractterminate(Integer id,Model modul){
		modul.addAttribute("id", id);
		Integer userid = BOXLoginInfoUtil.getLoginInfo().getLoginId();
		Map<String,Object> map = new HashMap<>();
		map.put("pageId", 14);
		map.put("userId", userid.toString());
		if(bls.getUserRole(map) != 0){
			return "huangyan/contractTerminate";
		}else{
			return "contract/notLimitsPage";
		}
	}
	
	@RequestMapping("getcustomer")
	@ResponseBody
	public CustomerEntity findUserContract(Integer id){
		Map<String,Object> map = new HashMap<>();
		map.put("id", id);
		return customerService.findUserContract(map);
	}
	@RequestMapping("list")
	@ResponseBody
	public Page<ContractEXEEntity> list(String id,Page<ContractEXEEntity> page){
		page.getSearch().put("id", id);
		contractEXEService.findListByCID(page.getSearch());
		return  page;
	}
	@RequestMapping("list1")
	@ResponseBody
	public List<ContractEXEEntity> list(String id){
		Map<String,Object> map = new HashMap<>();
		map.put("id", id);
		return contractEXEService.findListByCID(map);
		
	}
	@RequestMapping("findMax")
	@ResponseBody
	public ContractEXEEntity findMax(String id){
		return contractEXEService.findMax(id);
	}
	@RequestMapping("findSUM")
	@ResponseBody
	public String findSUM(String contractbaseid){
		return contractEXEService.findSUM(contractbaseid);
	}
	@RequestMapping("save")
	@ResponseBody
	public RespJson save(@Valid ContractBaseEntity con){
		Integer id = BOXLoginInfoUtil.getLoginInfo().getLoginId();
		con.setForceOperid(id.toString());
		
		cbs.updateById(con);
		
		return RespJsonFactory.buildSuccess();
	}
}
